<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/11 0011
  Time: 下午 4:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>

    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    <style>



    </style>
</head>
<body>
<%--<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">--%>
<%--<i class="layui-icon" style="line-height:30px">ဂ</i></a>--%>

<form class="layui-form" action="">

    <c:choose >
        <c:when test="${not empty logistics }">
            <div class="layui-form-item">
                <label class="layui-form-label">物流单号</label>
                <div class="layui-input-block">
                    <input type="text" name="id"
                           disabled="disabled" value="${logistics.logisticsId}"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">更新时间</label>
                <div class="layui-input-block">
                    <input type="text" name="id"
                           disabled="disabled" value="${logistics.upTime} "
                           class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">快递公司</label>
                <div class="layui-input-block">
                    <input type="text" name="id"
                           disabled="disabled" value="${logistics.name}"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">物流状态</label>
                <div class="layui-input-block">
                    <input type="text" name="id"
                           disabled="disabled"
                    <c:choose>
                    <c:when test="${logistics.state==1}">
                           value="暂无轨迹"
                    </c:when>
                    <c:when test="${logistics.state==2}">
                           value="在途中"
                    </c:when>
                    <c:when test="${logistics.state==3}">
                           value="已签收"
                    </c:when>
                    <c:when test="${order.state==4}">
                           value="问题件"
                    </c:when>

                    <c:otherwise>
                           value="未知情况"
                    </c:otherwise>
                    </c:choose>

                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">

                <label class="layui-form-label">轨迹信息</label>
                <table class="layui-table" cellspacing="0" cellpadding="0" border="0" >
                        <%--<thead>--%>
                        <%--<tr>--%>
                        <%--<th >商品</th>--%>
                        <%--<th >图片</th>--%>
                        <%--<th >数量</th>--%>
                        <%--<th >价格</th>--%>
                        <%--</tr>--%>
                        <%--</thead>--%>
                    <tbody>
                    <c:forEach items="${logistics.infoList}" var="logisticsInfo">
                        <tr>
                            <td>${logisticsInfo.time}</td>
                            <td>${logisticsInfo.content}</td>
                        </tr>

                    </c:forEach>

                    </tbody>
                </table>

            </div >
            <div class="layui-form-item">
                <label class="layui-form-label">物流单号</label>
                <div class="layui-input-block">
                    <input type="text" name="id"
                           disabled="disabled" value="${logistics.logisticsId}"
                           class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">

                <div class="layui-input-block">
                    <button class="layui-btn" type="button" onclick="upLogistics();">更新物流单号</button>
                </div>
            </div>




            <div  id="upLogistics" style="display:none;z-index: 99;!important;"> <%-- 更新订单--%>

                <input type="hidden" value="${orderId}" name="orderId">
                <div class="layui-form-item">
                    <label class="layui-form-label">物流单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="id"
                               value=""
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>

            </div>

            <script>

                function upLogistics() {
                    //$("#upLogistics").css('style', 'display:block  !important');
                    $("#upLogistics").show();

                }
            </script>

        </c:when>


        <c:otherwise>

                <input type="hidden" value="${orderId}" name="orderId">
                <div class="layui-form-item">
                    <label class="layui-form-label">物流单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="id"
                                value=""
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
                </div>
        </c:otherwise>
    </c:choose>

</form>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;


        //监听提交
        form.on('submit(demo1)', function(data){
            console.log(JSON.stringify(data.field))

            $.ajax({
                url:'/order/saveLogistics',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:data.field,
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                    console.log('发送前')*/
                },
                success:function(data){

                    console.log(data);
                    if (data.code=='000000'){
                        layer.msg(data.msg,{time:1000,icon: 6},function () {

                            window.location.href="/order/logistics?orderId=${orderId}";
                        });
                    }else {
                        layer.msg(data.msg,{time:1000,icon: 5});
                    }
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            })



            return false;
        });




    });
</script>



</body>

</html>
